<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="前端,">





  <link rel="alternate" href="/atom.xml" title="Mr.赵" type="application/atom+xml">






<meta name="description" content="没学明白呢QAQ">
<meta name="keywords" content="前端">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript">
<meta property="og:url" content="https://GodPang.github.io/2019/05/01/JavaScript/index.html">
<meta property="og:site_name" content="Mr.赵">
<meta property="og:description" content="没学明白呢QAQ">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmn4c2t6j30i007xgln.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmntc5l9j30kn05haa0.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmnzwjuij30kn05hq2w.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmoe2afrj313d0fpafh.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmouc7knj313d0fpafh.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmpk8c5uj30c107t3yq.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmv4zolaj30qx0ej0vu.jpg">
<meta property="og:updated_time" content="2019-05-05T09:20:20.978Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript">
<meta name="twitter:description" content="没学明白呢QAQ">
<meta name="twitter:image" content="https://ws1.sinaimg.cn/large/006doHETly1g2lmn4c2t6j30i007xgln.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://GodPang.github.io/2019/05/01/JavaScript/">





  <title>JavaScript | Mr.赵</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    
    <a href="https://GodPang.github.io" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Mr.赵</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-类别">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            类别
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://GodPang.github.io/2019/05/01/JavaScript/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="GodPang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/touxiang.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Mr.赵">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">JavaScript</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-05-01T11:04:10+08:00">
                2019-05-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/web学习/" itemprop="url" rel="index">
                    <span itemprop="name">web学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/05/01/JavaScript/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/05/01/JavaScript/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-eye"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <html><head><meta name="generator" content="Hexo 3.9.0"></head><body><h3>没学明白呢QAQ</h3>
<a id="more"></a>
# 一、JavaScript介绍

<p>JavaScript 编程语言   流程控制</p>
<p>Netscape在最初将其脚本语言命名为LiveScript，后来Netscape在与Sun合作之后将其改名为JavaScript。JavaScript最初受Java启发而开始设计的，目的之一就是“看上去像Java”，因此语法上有类似之处，一些名称和命名规范也借自Java。JavaScript与Java名称上的近似，是当时Netscape为了营销考虑与Sun微系统达成协议的结果。Java和JavaScript的关系就像张雨和张雨生的关系，只是名字很像。</p>
<p>​   Java  服务器端的编程语言</p>
<p>​   JavaScript  运行在客户端(浏览器)的编程语言</p>
<blockquote>
<p>JavaScript是一种运行在<strong><em>客户端</em></strong> 的<strong><em>脚本语言</em></strong><br>JavaScript的解释器被称为JavaScript引擎，为浏览器的一部分，广泛用于客户端的脚本语言，最早是在HTML（标准通用标记语言下的一个应用）网页上使用，用来给HTML网页增加动态功能。</p>
</blockquote>
<h2 id="1、JavaScript现在的意义-应用场景"><a href="#1、JavaScript现在的意义-应用场景" class="headerlink" title="1、JavaScript现在的意义(应用场景)"></a>1、JavaScript现在的意义(应用场景)</h2><p>JavaScript 发展到现在几乎无所不能。</p>
<ol>
<li>网页特效</li>
<li>服务端开发(Node.js)</li>
<li>命令行工具(Node.js)</li>
<li>桌面程序(Electron)</li>
<li>App(Cordova)</li>
<li>控制硬件-物联网(Ruff)</li>
<li>游戏开发(cocos2d-js)</li>
</ol>
<h2 id="2、JavaScript和HTML、CSS的区别"><a href="#2、JavaScript和HTML、CSS的区别" class="headerlink" title="2、JavaScript和HTML、CSS的区别"></a>2、JavaScript和HTML、CSS的区别</h2><ol>
<li><p>HTML：提供网页的结构，提供网页中的内容</p>
</li>
<li><p>CSS: 用来美化网页</p>
</li>
<li><p>JavaScript: 可以用来控制网页内容，给网页增加动态的效果，例如动态创建div,实现页面元素的隐藏。</p>
</li>
</ol>
<h2 id="3、JavaScript的组成"><a href="#3、JavaScript的组成" class="headerlink" title="3、JavaScript的组成"></a>3、JavaScript的组成</h2><p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmn4c2t6j30i007xgln.jpg" alt=""></p>
<h3 id="3-1、ECMAScript-JavaScript的核心"><a href="#3-1、ECMAScript-JavaScript的核心" class="headerlink" title="3.1、ECMAScript - JavaScript的核心"></a>3.1、ECMAScript - JavaScript的核心</h3><p>定义了JavaScript的语法规范</p>
<p>JavaScript的核心，描述了语言的基本语法和数据类型，ECMAScript是一套标准，定义了一种语言的标准与具体实现无关</p>
<h3 id="3-2、BOM-浏览器对象模型"><a href="#3-2、BOM-浏览器对象模型" class="headerlink" title="3.2、BOM - 浏览器对象模型"></a>3.2、BOM - 浏览器对象模型</h3><p>一套操作浏览器功能的API</p>
<p>通过BOM可以操作浏览器窗口，比如：弹出框、控制浏览器跳转、获取分辨率等</p>
<h3 id="3-3、DOM-文档对象模型"><a href="#3-3、DOM-文档对象模型" class="headerlink" title="3.3、DOM - 文档对象模型"></a>3.3、DOM - 文档对象模型</h3><p>一套操作页面元素的API</p>
<p>DOM可以把HTML看做是文档树，通过DOM提供的API可以对树上的节点进行操作</p>
<h3 id="3-4、JavaScript的书写位置"><a href="#3-4、JavaScript的书写位置" class="headerlink" title="3.4、JavaScript的书写位置"></a>3.4、JavaScript的书写位置</h3><ul>
<li>写在行内</li>
</ul>
<figure class="highlight html"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">input</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">value</span>=<span class="string">"按钮"</span> <span class="attr">onclick</span>=<span class="string">"alert('Hello World')"</span> /></span></span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>写在script标签中</li>
</ul>
<figure class="highlight html"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line">  <span class="tag"><<span class="name">script</span>></span><span class="undefined"></span></span><br><span class="line"><span class="undefined">    alert('Hello World!');</span></span><br><span class="line"><span class="undefined">  </span><span class="tag">script</span>></span><br><span class="line"><span class="tag">head</span>></span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>写在外部js文件中，在页面引入</li>
</ul>
<figure class="highlight html"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"main.js"</span>></span><span class="undefined"></span><span class="tag">script</span>></span><br></pre></td></tr></tbody></table></figure>

<ul>
<li><p>注意点</p>
<p><strong><em>引用外部js文件的script标签中不可以写JavaScript代码</em></strong></p>
</li>
</ul>
<h1 id="二、变量"><a href="#二、变量" class="headerlink" title="二、变量"></a>二、变量</h1><h3 id="1、什么是变量"><a href="#1、什么是变量" class="headerlink" title="1、什么是变量"></a>1、什么是变量</h3><ul>
<li><p>什么是变量</p>
<p>变量是计算机内存中存储数据的标识符，根据变量名称可以获取到内存中存储的数据</p>
<p>变量用于描述计算机中的数据存储空间 。</p>
<p>房屋是一个存储空间</p>
<p>用来存放特定的东西</p>
<p>内存，全称内存储器。用于存放计算机运行过程中的数据。</p>
<p>计算机为了更好的存储数据，将内存分为不同的内存单元。</p>
<p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmntc5l9j30kn05haa0.jpg" alt=""></p>
</li>
<li><p>为什么要使用变量</p>
<p>从内存中取出一个存储单元，存储相应的数据。</p>
<p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmnzwjuij30kn05hq2w.jpg" alt=""></p>
<p>为了方便存储数据和取数据，需要明确存储单元识别的方式和使用的用途。</p>
<p>识别的方式：起名字 age</p>
<p>使用用途：存放什么内容   18</p>
<p>使用变量可以方便的获取或者修改内存中的数据</p>
</li>
</ul>
<h3 id="2、如何使用变量"><a href="#2、如何使用变量" class="headerlink" title="2、如何使用变量"></a>2、如何使用变量</h3><ul>
<li>var声明变量</li>
</ul>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> age;</span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>变量的赋值</li>
</ul>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> age;</span><br><span class="line">age = <span class="number">18</span>;</span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>同时声明多个变量</li>
</ul>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> age, name, sex;</span><br><span class="line">age = <span class="number">10</span>;</span><br><span class="line">name = <span class="string">'zs'</span>;</span><br></pre></td></tr></tbody></table></figure>

<ul>
<li>同时声明多个变量并赋值</li>
</ul>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">10</span>, name = <span class="string">'zs'</span>;</span><br></pre></td></tr></tbody></table></figure>

<h3 id="3、变量在内存中的存储"><a href="#3、变量在内存中的存储" class="headerlink" title="3、变量在内存中的存储"></a>3、变量在内存中的存储</h3><p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmoe2afrj313d0fpafh.jpg" alt=""></p>
<h3 id="4、变量的命名规则和规范"><a href="#4、变量的命名规则和规范" class="headerlink" title="4、变量的命名规则和规范"></a>4、变量的命名规则和规范</h3><ul>
<li><p>规则 - 必须遵守的，不遵守会报错</p>
<ul>
<li>由字母、数字、下划线、$符号组成，不能以数字开头</li>
<li>不能是关键字和保留字，例如：for、while。</li>
<li>区分大小写</li>
</ul>
</li>
<li><p>规范 - 建议遵守的，不遵守不会报错</p>
<ul>
<li>变量名必须有意义</li>
<li>遵守驼峰命名法。首字母小写，后面单词的首字母需要大写。例如：userName、userPassword</li>
</ul>
<p>下面哪些变量名不合法</p>
<p>  a<br>  1<br>  age18<br>  18age<br>  name<br>  $name<br>  _sex<br>  &sex<br>  theworld  theWorld</p>
</li>
</ul>
<h3 id="5、交换两个变量中的值-案例"><a href="#5、交换两个变量中的值-案例" class="headerlink" title="5、交换两个变量中的值(案例)"></a>5、交换两个变量中的值(案例)</h3><h1 id="三、数据类型"><a href="#三、数据类型" class="headerlink" title="三、数据类型"></a>三、数据类型</h1><p>数据类型分为，“简单数据类型”和“复杂数据类型”，现在我们先学习“简单的数据类型”</p>
<p>简单数据类型</p>
<p>Number、String、Boolean、Undefined、Null</p>
<h2 id="1、Number类型"><a href="#1、Number类型" class="headerlink" title="1、Number类型"></a>1、Number类型</h2><ul>
<li><p>数值字面量：数值的固定值的表示法</p>
<p>110 1024  60.5</p>
<p> 浮点数</p>
<p>浮点数精度的问题。</p>
</li>
</ul>
<pre><code>浮点数
    var n = 5e-324;   // 科学计数法  5乘以10的-324次方
浮点数值的最高精度是 17 位小数，但在进行算术计算时其精确度远远不如整数
   var result = 0.1 + 0.2;    // 结果不是 0.3，而是：0.30000000000000004
   console.log(0.07 * 100);
   不要判断两个浮点数是否相等</code></pre><p>数值判断</p>
<ul>
<li><p>NaN：not a number</p>
<ul>
<li><p>NaN 与任何值都不相等，包括他本身</p>
<p>在控制台中使用 6*‘abc’  可以输出NaN</p>
</li>
</ul>
</li>
<li><p>isNaN: is not a number</p>
<p> 是数字返回为false.</p>
<p>不是数字返回true.</p>
</li>
</ul>
<h2 id="2、String类型"><a href="#2、String类型" class="headerlink" title="2、String类型"></a>2、String类型</h2><p><strong>字符串</strong></p>
<p>​   ‘abc’   “abc”</p>
<p>‘程序猿’，’程序媛’, “黑马程序猿”</p>
<p>思考：如何打印以下字符串。<br>我是一个”正直”的人<br>我很喜欢”黑马’程序猿’”<br>测试字符串中的字符个数:</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(msg.length);</span><br></pre></td></tr></tbody></table></figure>

<h3 id="2-2-1-转义符"><a href="#2-2-1-转义符" class="headerlink" title="2.2.1 转义符"></a>2.2.1 <strong>转义符</strong></h3><p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmouc7knj313d0fpafh.jpg" alt=""></p>
<p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmpk8c5uj30c107t3yq.jpg" alt=""></p>
<h3 id="2-2-2-字符串长度"><a href="#2-2-2-字符串长度" class="headerlink" title="2.2.2 字符串长度"></a>2.2.2 字符串长度</h3><p>length属性用来获取字符串的长度</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">'黑马程序猿 Hello World'</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.length);</span><br></pre></td></tr></tbody></table></figure>

<h3 id="2-2-3-字符串拼接"><a href="#2-2-3-字符串拼接" class="headerlink" title="2.2.3 字符串拼接"></a>2.2.3 字符串拼接</h3><p>字符串拼接使用 + 连接</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="number">11</span> + <span class="number">11</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'hello'</span> + <span class="string">' world'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'100'</span> + <span class="string">'100'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'11'</span> + <span class="number">11</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'male:'</span> + <span class="literal">true</span>);</span><br></pre></td></tr></tbody></table></figure>

<ol>
<li>两边只要有一个是字符串，那么+就是字符串拼接功能</li>
<li>两边如果都是数字，那么就是算术功能。</li>
</ol>
<h2 id="3、Boolean类型"><a href="#3、Boolean类型" class="headerlink" title="3、Boolean类型"></a>3、Boolean类型</h2><ul>
<li>Boolean字面量：  true和false，区分大小写</li>
<li>计算机内部存储：true为1，false为0</li>
</ul>
<h2 id="4、Undefined和Null"><a href="#4、Undefined和Null" class="headerlink" title="4、Undefined和Null"></a>4、Undefined和Null</h2><ol>
<li>undefined表示一个声明了没有赋值的变量，变量只声明的时候值默认是undefined</li>
<li>null表示一个空，变量的值如果想为null，必须手动设置</li>
</ol>
<h2 id="5、获取变量的类型"><a href="#5、获取变量的类型" class="headerlink" title="5、获取变量的类型"></a>5、获取变量的类型</h2><p>typeof</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> age = <span class="number">18</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> age);  <span class="comment">// 'number'</span></span><br></pre></td></tr></tbody></table></figure>

<h1 id="四、注释"><a href="#四、注释" class="headerlink" title="四、注释"></a>四、注释</h1><h2 id="4-1-单行注释"><a href="#4-1-单行注释" class="headerlink" title="4.1 单行注释"></a>4.1 单行注释</h2><p>用来描述下面一个或多行代码的作用</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 这是一个变量</span></span><br><span class="line"><span class="keyword">var</span> name = <span class="string">'hm'</span>;</span><br></pre></td></tr></tbody></table></figure>

<h2 id="4-2-多行注释"><a href="#4-2-多行注释" class="headerlink" title="4.2 多行注释"></a>4.2 多行注释</h2><p>用来注释多条代码</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">var age = 18;</span></span><br><span class="line"><span class="comment">var name = 'zs';</span></span><br><span class="line"><span class="comment">console.log(name, age);</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></tbody></table></figure>

<h1 id="五、操作符"><a href="#五、操作符" class="headerlink" title="五、操作符"></a>五、操作符</h1><h2 id="5-1-算术运算符"><a href="#5-1-算术运算符" class="headerlink" title="5.1 算术运算符"></a>5.1 算术运算符</h2><pre><code>+ - * / %</code></pre><h2 id="5-2-一元运算符"><a href="#5-2-一元运算符" class="headerlink" title="5.2  一元运算符"></a>5.2  一元运算符</h2><p>一元运算符：只有一个操作数的运算符</p>
<p>5 + 6  两个操作数的运算符 二元运算符</p>
<p>++  自身加1</p>
<p>-- 自身减1</p>
<p><strong>前置++</strong></p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num1 = <span class="number">5</span>;</span><br><span class="line">++ num1;</span><br></pre></td></tr></tbody></table></figure>

<p><strong>后置++</strong></p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> num1 = <span class="number">5</span>;</span><br><span class="line">num1 ++;</span><br></pre></td></tr></tbody></table></figure>

<p>思考题：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">var</span> b = ++a + ++a;</span><br><span class="line"><span class="built_in">console</span>.log(b);</span><br></pre></td></tr></tbody></table></figure>

<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">var</span> b = a++ + a++;</span><br><span class="line"> <span class="built_in">console</span>.log(b);</span><br></pre></td></tr></tbody></table></figure>

<h2 id="5-3-逻辑运算符-布尔运算符"><a href="#5-3-逻辑运算符-布尔运算符" class="headerlink" title="5.3 逻辑运算符(布尔运算符)"></a>5.3 逻辑运算符(布尔运算符)</h2><pre><code>&& 与 两个操作数同时为true，结果为true，否则都是false
|| 或 两个操作数有一个为true，结果为true，否则为false
!  非  取反</code></pre><h2 id="5-4-关系运算符-比较运算符"><a href="#5-4-关系运算符-比较运算符" class="headerlink" title="5.4 关系运算符(比较运算符)"></a>5.4 关系运算符(比较运算符)</h2><pre><code><  >  >=  <= =="!=" !="=</code"></=></code></pre><figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">==与===的区别：==只进行值得比较，===类型和值同时相等，则相等</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> result = <span class="string">'55'</span> == <span class="number">55</span>;    <span class="comment">// true</span></span><br><span class="line"><span class="keyword">var</span> result = <span class="string">'55'</span> === <span class="number">55</span>;   <span class="comment">// false 值相等，类型不相等</span></span><br><span class="line"><span class="keyword">var</span> result = <span class="number">55</span> === <span class="number">55</span>;     <span class="comment">// true</span></span><br></pre></td></tr></tbody></table></figure>

<h2 id="5-5-赋值运算符"><a href="#5-5-赋值运算符" class="headerlink" title="5.5 赋值运算符"></a>5.5 赋值运算符</h2><p>=   +=   -=   *=   /=   %=</p>
<pre><code>例如：
var num = 0;
num += 5;   //相当于  num = num + 5;</code></pre><h2 id="5-6-运算符的优先级"><a href="#5-6-运算符的优先级" class="headerlink" title="5.6 运算符的优先级"></a>5.6 运算符的优先级</h2><pre><code>优先级从高到底
    1. ()  优先级最高
    2. 一元运算符  ++   --   !
    3. 算数运算符  先*  /  %   后 +   -
    4. 关系运算符  >   >=   <   <= 5.="" 相等运算符="=" !="===" 6.="" 逻辑运算符="" 先&&="" 后||="" 7.="" 赋值运算符<="" code=""></=></code></pre><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">（<span class="number">4</span> >= <span class="number">6</span>） || （<span class="string">'人'</span> != <span class="string">'阿凡达'</span>） && (!(<span class="number">12</span> * <span class="number">2</span> == <span class="number">144</span>)) && <span class="literal">true</span></span><br><span class="line">                <span class="literal">false</span>||<span class="literal">true</span></span><br><span class="line">由于|| 和&& 运算级别最低，因为在该表达式中没有赋值，所以可以加上小括号。</span><br></pre></td></tr></tbody></table></figure>

<h1 id="六、流程控制"><a href="#六、流程控制" class="headerlink" title="六、流程控制"></a>六、流程控制</h1><blockquote>
<p>程序的三种基本结构</p>
</blockquote>
<h3 id="顺序结构"><a href="#顺序结构" class="headerlink" title="顺序结构"></a>顺序结构</h3><p> 从上到下执行的代码就是顺序结构</p>
<p><strong>程序默认就是由上到下顺序执行的</strong></p>
<h3 id="分支结构"><a href="#分支结构" class="headerlink" title="分支结构"></a>分支结构</h3><p>根据不同的情况，执行对应代码</p>
<h3 id="循环结构"><a href="#循环结构" class="headerlink" title="循环结构"></a>循环结构</h3><p>循环结构：重复做一件事情</p>
<h2 id="6-1-分支结构"><a href="#6-1-分支结构" class="headerlink" title="6.1 分支结构"></a>6.1 分支结构</h2><h3 id="if语句"><a href="#if语句" class="headerlink" title="if语句"></a>if语句</h3><p>语法结构</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (<span class="comment">/* 条件表达式 */</span>) {</span><br><span class="line">  <span class="comment">// 执行语句</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (<span class="comment">/* 条件表达式 */</span>){</span><br><span class="line">  <span class="comment">// 成立执行语句</span></span><br><span class="line">} <span class="keyword">else</span> {</span><br><span class="line">  <span class="comment">// 否则执行语句</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (<span class="comment">/* 条件1 */</span>){</span><br><span class="line">  <span class="comment">// 成立执行语句</span></span><br><span class="line">} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="comment">/* 条件2 */</span>){</span><br><span class="line">  <span class="comment">// 成立执行语句</span></span><br><span class="line">} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="comment">/* 条件3 */</span>){</span><br><span class="line">  <span class="comment">// 成立执行语句</span></span><br><span class="line">} <span class="keyword">else</span> {</span><br><span class="line">  <span class="comment">// 最后默认执行语句</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<p>案例：1、求两个数的最大数<br>        2、判断一个数是偶数还是奇数<br>     3、分数转换，把百分制转换成ABCDE   <60 90="" 100="" e="" 60-70="" d="" 70-80="" c="" 80-90="" b="" -="" a<="" p="">
<h2 id="6-2-循环结构"><a href="#6-2-循环结构" class="headerlink" title="6.2 循环结构"></a>6.2 循环结构</h2><p>在javascript中，循环语句有三种，while、do..while、for循环。</p>
<h3 id="while语句"><a href="#while语句" class="headerlink" title="while语句"></a>while语句</h3><p>基本语法：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 当循环条件为true时，执行循环体，</span></span><br><span class="line"><span class="comment">// 当循环条件为false时，结束循环。</span></span><br><span class="line"><span class="keyword">while</span> (循环条件) {</span><br><span class="line">  <span class="comment">//循环体</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<p>代码示例：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 计算1-100之间所有数的和</span></span><br><span class="line"><span class="comment">// 初始化变量</span></span><br><span class="line"><span class="keyword">var</span> i = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">var</span> sum = <span class="number">0</span>;</span><br><span class="line"><span class="comment">// 判断条件</span></span><br><span class="line"><span class="keyword">while</span> (i <= <span="" class="number">100</=></span>) {<br><span class="line">  <span class="comment">// 循环体</span></span><br><span class="line">  sum += i;</span><br><span class="line">  <span class="comment">// 自增</span></span><br><span class="line">  i++;</span><br><span class="line">}</span><br><span class="line"><span class="built_in">console</span>.log(sum);</span><br></pre></td></tr></tbody></table></figure>

<p><strong>案例：打印100以内所有偶数的和(作业1)</strong></p>
<h3 id="do…while语句"><a href="#do…while语句" class="headerlink" title="do…while语句"></a><strong>do…while语句</strong></h3><blockquote>
<p>do..while循环和while循环非常像，二者经常可以相互替代，但是do..while的特点是不管条件成不成立，都会执行一次。</p>
</blockquote>
<p>基础语法：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">do</span> {</span><br><span class="line">  <span class="comment">// 循环体;</span></span><br><span class="line">} <span class="keyword">while</span> (循环条件);</span><br></pre></td></tr></tbody></table></figure>

<p>代码示例：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 初始化变量</span></span><br><span class="line"><span class="keyword">var</span> i = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">var</span> sum = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">do</span> {</span><br><span class="line">  sum += i;<span class="comment">//循环体</span></span><br><span class="line">  i++;<span class="comment">//自增</span></span><br><span class="line">} <span class="keyword">while</span> (i <= <span="" class="number">100</=></span>);<span class="comment">//循环条件</span><br></pre></td></tr></tbody></table></figure>

<h3 id="for语句"><a href="#for语句" class="headerlink" title="for语句"></a>for语句</h3><p>for循环语法：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// for循环的表达式之间用的是;号分隔的，千万不要写成,</span></span><br><span class="line"><span class="keyword">for</span> (初始化表达式<span class="number">1</span>; 判断表达式<span class="number">2</span>; 自增表达式<span class="number">3</span>) {</span><br><span class="line">  <span class="comment">// 循环体4</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<p>执行顺序：1243  —-  243   —–243(直到循环条件变成false)</p>
<ol>
<li><p>初始化表达式</p>
</li>
<li><p>判断表达式</p>
</li>
<li><p>自增表达式</p>
</li>
<li><p>循环体</p>
</li>
</ol>
<h1 id="七、数组"><a href="#七、数组" class="headerlink" title="七、数组"></a>七、数组</h1><h3 id="为什么要学习数组"><a href="#为什么要学习数组" class="headerlink" title="为什么要学习数组"></a>为什么要学习数组</h3><blockquote>
<p>之前学习的数据类型，只能存储一个值(比如：Number/String。我们想存储班级中所有学生的姓名，此时该如何存储？</p>
</blockquote>
<h3 id="数组的概念"><a href="#数组的概念" class="headerlink" title="数组的概念"></a>数组的概念</h3><blockquote>
<p>所谓数组，就是将多个元素（通常是同一类型）按一定顺序排列放到一个集合中，那么这个集合我们就称之为数组。</p>
</blockquote>
<h3 id="数组的定义"><a href="#数组的定义" class="headerlink" title="数组的定义"></a>数组的定义</h3><blockquote>
<p>数组是一个有序的列表，可以在数组中存放任意的数据，并且数组的长度可以动态的调整。</p>
</blockquote>
<p>   通过数组字面量创建数组</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建一个空数组</span></span><br><span class="line"><span class="keyword">var</span> arr1 = [];</span><br><span class="line"><span class="comment">// 创建一个包含3个数值的数组，多个数组项以逗号隔开</span></span><br><span class="line"><span class="keyword">var</span> arr2 = [<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line"><span class="comment">// 创建一个包含2个字符串的数组</span></span><br><span class="line"><span class="keyword">var</span> arr3 = [<span class="string">'a'</span>, <span class="string">'c'</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可以通过数组的length属性获取数组的长度</span></span><br><span class="line"><span class="built_in">console</span>.log(arr3.length);</span><br><span class="line"><span class="comment">// 可以设置length属性改变数组中元素的个数</span></span><br><span class="line">arr3.length = <span class="number">0</span>;</span><br></pre></td></tr></tbody></table></figure>

<p>获取数组元素</p>
<p>数组的取值</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 格式：数组名[下标]   下标又称索引</span></span><br><span class="line"><span class="comment">// 功能：获取数组对应下标的那个值，如果下标不存在，则返回undefined。</span></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="string">'red'</span>,, <span class="string">'green'</span>, <span class="string">'blue'</span>];</span><br><span class="line">arr[<span class="number">0</span>]; <span class="comment">// red</span></span><br><span class="line">arr[<span class="number">2</span>]; <span class="comment">// blue</span></span><br><span class="line">arr[<span class="number">3</span>]; <span class="comment">// 这个数组的最大下标为2,因此返回undefined</span></span><br></pre></td></tr></tbody></table></figure>

<h3 id="遍历数组"><a href="#遍历数组" class="headerlink" title="遍历数组"></a>遍历数组</h3><blockquote>
<p>遍历：遍及所有，对数组的每一个元素都访问一次就叫遍历。</p>
</blockquote>
<p>数组遍历的基本语法：</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span>; i < arr.length; i++) {</span><br><span class="line">    <span class="comment">// 数组遍历的固定结构</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<h3 id="数组中新增元素"><a href="#数组中新增元素" class="headerlink" title="数组中新增元素"></a>数组中新增元素</h3><p>数组的赋值</p>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 格式：数组名[下标/索引] = 值;</span></span><br><span class="line"><span class="comment">// 如果下标有对应的值，会把原来的值覆盖，如果下标不存在，会给数组新增一个元素。</span></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="string">"red"</span>, <span class="string">"green"</span>, <span class="string">"blue"</span>];</span><br><span class="line"><span class="comment">// 把red替换成了yellow</span></span><br><span class="line">arr[<span class="number">0</span>] = <span class="string">"yellow"</span>;</span><br><span class="line"><span class="comment">// 给数组新增加了一个pink的值</span></span><br><span class="line">arr[<span class="number">3</span>] = <span class="string">"pink"</span>;</span><br></pre></td></tr></tbody></table></figure>

<h1 id="八、函数"><a href="#八、函数" class="headerlink" title="八、函数"></a>八、函数</h1><h2 id="一、为什么要有函数"><a href="#一、为什么要有函数" class="headerlink" title="一、为什么要有函数"></a>一、为什么要有函数</h2><blockquote>
<p>如果要在多个地方求1-100之间所有数的和，应该怎么做？</p>
</blockquote>
<h2 id="二、什么是函数"><a href="#二、什么是函数" class="headerlink" title="二、什么是函数"></a>二、什么是函数</h2><blockquote>
<p>把一段相对独立的具有特定功能的代码块封装起来，形成一个独立实体，就是函数，起个名字（函数名），在后续开发中可以反复调用</p>
<p>函数的作用就是封装一段代码，将来可以重复使用</p>
</blockquote>
<h3 id="2-1-函数的定义"><a href="#2-1-函数的定义" class="headerlink" title="2.1 函数的定义"></a>2.1 函数的定义</h3><p>函数声明</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> 函数名(<span class="params"></span>) </span>{</span><br><span class="line">     <span class="comment">// 函数体</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<p>特点：</p>
<p>函数声明的时候，函数体并不会执行，只要当函数被调用的时候才会执行。<br>函数一般都用来干一件事情，函数名称一般使用动词</p>
<h3 id="2-2-函数的调用"><a href="#2-2-函数的调用" class="headerlink" title="2.2 函数的调用"></a>2.2 函数的调用</h3><ul>
<li>调用函数的语法：</li>
</ul>
<figure class="highlight javascript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">函数名();</span><br></pre></td></tr></tbody></table></figure>

<ul>
<li><p>特点：</p>
<p>函数体只有在调用的时候才会执行，调用需要()进行调用。<br>可以调用多次(重复使用)</p>
<p>代码示例：</p>
</li>
</ul>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明函数</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">sayHi</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">"吃了没？"</span>);</span><br><span class="line">}</span><br><span class="line"><span class="comment">// 调用函数</span></span><br><span class="line">sayHi();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 求1-100之间所有数的和</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getSum</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="keyword">var</span> sum = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">var</span>  i = <span class="number">0</span>; i < <span class="number">100</span>; i++) {</span><br><span class="line">    sum += i;</span><br><span class="line">  }</span><br><span class="line">  <span class="built_in">console</span>.log(sum);</span><br><span class="line">}</span><br><span class="line"><span class="comment">// 调用</span></span><br><span class="line">getSum();</span><br></pre></td></tr></tbody></table></figure>

<h3 id="2-3-函数的参数"><a href="#2-3-函数的参数" class="headerlink" title="2.3 函数的参数"></a>2.3 函数的参数</h3><p>为什么要有参数</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getSum</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="keyword">var</span> sum = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">1</span>; i <= <span="" class="number">100</=></span>; i++) {<br><span class="line">    sum += i;</span><br><span class="line">  }</span><br><span class="line">  <span class="built_in">console</span>.log();</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 虽然上面代码可以重复调用，但是只能计算1-100之间的值</span></span><br><span class="line"><span class="comment">// 如果想要计算n-m之间所有数的和，应该怎么办呢？</span></span><br></pre></td></tr></tbody></table></figure>

<p>语法：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 函数内部是一个封闭的环境，可以通过参数的方式，把外部的值传递给函数内部</span></span><br><span class="line"><span class="comment">// 带参数的函数声明</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> 函数名(<span class="params">形参<span class="number">1</span>, 形参<span class="number">2</span>, 形参<span class="number">3.</span>..</span>) </span>{</span><br><span class="line">  <span class="comment">// 函数体</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 带参数的函数调用</span></span><br><span class="line">函数名(实参<span class="number">1</span>, 实参<span class="number">2</span>, 实参<span class="number">3</span>);</span><br><span class="line">形参<span class="number">1</span> = 实参<span class="number">1</span></span><br><span class="line">形参<span class="number">2</span> = 实参<span class="number">2</span></span><br></pre></td></tr></tbody></table></figure>

<p>形参和实参</p>
<blockquote>
<ol>
<li><p>形式参数：在声明一个函数的时候，为了函数的功能更加灵活，有些值是固定不了的，对于这些固定不了的值。我们可以给函数设置参数。这个参数没有具体的值，仅仅起到一个占位置的作用，我们通常称之为形式参数，也叫形参。</p>
</li>
<li><p>实际参数：如果函数在声明时，设置了形参，那么在函数调用的时候就需要传入对应的参数，我们把传入的参数叫做实际参数，也叫实参。</p>
</li>
</ol>
</blockquote>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> x = <span class="number">5</span>, y = <span class="number">6</span>;</span><br><span class="line">fn(x,y);</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params">a, b</span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(a + b);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<p><strong>案例</strong></p>
<p><strong>求n-m之间所有数的和(作业1)</strong></p>
<p>n=100</p>
<p>m=200</p>
<p>function getSum(n,m){</p>
<p>}</p>
<h3 id="2-4-函数的返回值"><a href="#2-4-函数的返回值" class="headerlink" title="2.4 函数的返回值"></a>2.4 函数的返回值</h3><p>函数执行完的时候，并不是所有时候都要把结果打印。我们期望函数给我一些反馈（比如计算的结果返回进行后续的运算），这个时候可以让函数返回一些东西。也就是返回值。函数通过return返回一个返回值</p>
<p>返回值语法：</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//声明一个带返回值的函数</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> 函数名(<span class="params">形参<span class="number">1</span>, 形参<span class="number">2</span>, 形参<span class="number">3.</span>..</span>) </span>{</span><br><span class="line">  <span class="comment">//函数体</span></span><br><span class="line">  <span class="keyword">return</span> 返回值;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">//可以通过变量来接收这个返回值</span></span><br><span class="line"><span class="keyword">var</span> 变量 = 函数名(实参<span class="number">1</span>, 实参<span class="number">2</span>, 实参<span class="number">3.</span>..);</span><br></pre></td></tr></tbody></table></figure>

<p>函数的调用结果就是返回值，因此我们可以直接对函数调用结果进行操作。</p>
<h3 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h3><ul>
<li>求组数中的最大值</li>
<li><strong>求组数中的最小值（作业2）</strong></li>
</ul>
<p>返回值详解：</p>
<pre><code>如果函数没有显示的使用 return语句 ，那么函数有默认的返回值：undefined
如果函数使用 return语句，那么跟再return后面的值，就成了函数的返回值
如果函数使用 return语句，但是return后面没有任何值，那么函数的返回值也是：undefined
函数使用return语句后，这个函数会在执行完 return 语句之后停止并立即退出，也就是说return后面的所有其他代码都不会再执行。</code></pre><h1 id="九、什么是对象"><a href="#九、什么是对象" class="headerlink" title="九、什么是对象"></a>九、什么是对象</h1><pre><code>现实生活中：万物皆对象，对象是一个具体的事物，一个具体的事物就会有行为和特征。
举例： 一部车，一个手机
车是一类事物，门口停的那辆车才是对象
    特征：红色、四个轮子
    行为：驾驶、刹车</code></pre><h2 id="1、JavaScript中的对象"><a href="#1、JavaScript中的对象" class="headerlink" title="1、JavaScript中的对象"></a>1、JavaScript中的对象</h2><pre><code>JavaScript中的对象其实就是生活中对象的一个抽象
JavaScript的对象是无序属性的集合。
    其属性可以包含基本值、对象或函数。对象就是一组没有顺序的值。我们可以把JavaScript中的对象想象成键值对，其中值可以是数据和函数。
对象的行为和特征
    特征---属性
    行为---方法</code></pre><ul>
<li>事物的特征在对象中用属性来表示。</li>
<li>事物的行为在对象中用方法来表示。</li>
</ul>
<h2 id="2、为什么要有对象"><a href="#2、为什么要有对象" class="headerlink" title="2、为什么要有对象"></a>2、为什么要有对象</h2><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">printPerson</span>(<span class="params">name, age, sex....</span>) </span>{</span><br><span class="line">}</span><br><span class="line"><span class="comment">// 函数的参数如果特别多的话，可以使用对象简化</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">printPerson</span>(<span class="params">person</span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(person.name);</span><br><span class="line">  ……</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<h2 id="3、-对象创建"><a href="#3、-对象创建" class="headerlink" title="3、 对象创建"></a>3、 对象创建</h2><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> o = {</span><br><span class="line">  name: <span class="string">'zs,</span></span><br><span class="line"><span class="string">  age: 18,</span></span><br><span class="line"><span class="string">  sex: true,</span></span><br><span class="line"><span class="string">  sayHi: function () {</span></span><br><span class="line"><span class="string">    console.log(this.name);</span></span><br><span class="line"><span class="string">  }</span></span><br><span class="line"><span class="string">};</span></span><br></pre></td></tr></tbody></table></figure>

<p>通过构造函数来创建对象。(第一个单词的第一个字母大写，后续的每一个单词的第一个字母都大写)</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params">name, age, job</span>)</span>{</span><br><span class="line">  <span class="keyword">this</span>.name = name;</span><br><span class="line">  <span class="keyword">this</span>.age = age;</span><br><span class="line">  <span class="keyword">this</span>.job = job;</span><br><span class="line">  <span class="keyword">this</span>.sayHi = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'Hello,everyBody'</span>);</span><br><span class="line">  }</span><br><span class="line">}</span><br><span class="line"><span class="keyword">var</span> p1 = <span class="keyword">new</span> Person(<span class="string">'张三'</span>, <span class="number">22</span>, <span class="string">'actor'</span>);</span><br><span class="line"><span class="keyword">var</span> p2 = <span class="keyword">new</span> Person(<span class="string">'李四'</span>,<span class="number">20</span>, <span class="string">'student'</span>);</span><br><span class="line">p1.sayHi();</span><br></pre></td></tr></tbody></table></figure>

<h2 id="4、属性和方法"><a href="#4、属性和方法" class="headerlink" title="4、属性和方法"></a>4、属性和方法</h2><p>、</p>
<pre><code>如果一个变量属于一个对象所有，那么该变量就可以称之为该对象的一个属性，属性一般是名词，用来描述事物的特征
如果一个函数属于一个对象所有，那么该函数就可以称之为该对象的一个方法，方法是动词，描述事物的行为和功能</code></pre><h2 id="5、new关键字"><a href="#5、new关键字" class="headerlink" title="5、new关键字"></a>5、new关键字</h2><p>构造函数 ，是一种特殊的函数。主要用来在创建对象时初始化对象， 即为对象成员变量赋初始值，总与new运算符一起使用在创建对象的语句中。</p>
<ol>
<li>构造函数用于创建一类对象，首字母要大写。</li>
<li>构造函数要和new一起使用才有意义。</li>
</ol>
<p>new在执行时会做四件事情</p>
<pre><code>new会在内存中创建一个新的空对象
new 会让this指向这个新的对象
执行构造函数  目的：给这个新对象加属性和方法
new会返回这个新对象</code></pre><h2 id="3-6-this详解"><a href="#3-6-this详解" class="headerlink" title="3.6 this详解"></a>3.6 this详解</h2><pre><code>JavaScript中的this指向问题，有时候会让人难以捉摸，随着学习的深入，我们可以逐渐了解
现在我们需要掌握函数内部的this几个特点
    1. 函数在定义的时候this是不确定的，只有在调用的时候才可以确定
    2. 一般函数直接执行，内部this指向全局window
    3. 函数作为一个对象的方法，被该对象所调用，那么this指向的是该对象
    4. 构造函数中的this其实是一个隐式对象，类似一个初始化的模型，所有方法和属性都挂载到了这个隐式对象身上，后续通过new关键字来调用，从而实现实例化</code></pre><h1 id="十、什么是DOM"><a href="#十、什么是DOM" class="headerlink" title="十、什么是DOM"></a>十、什么是DOM</h1><h2 id="1、DOM的概念"><a href="#1、DOM的概念" class="headerlink" title="1、DOM的概念"></a>1、DOM的概念</h2><p>文档对象模型（Document Object Model，简称DOM），是<a href="https://baike.baidu.com/item/W3C" target="_blank" rel="noopener">W3C</a>组织推荐的处理<a href="https://baike.baidu.com/item/%E5%8F%AF%E6%89%A9%E5%B1%95%E7%BD%AE%E6%A0%87%E8%AF%AD%E8%A8%80" target="_blank" rel="noopener">可扩展标记语言</a>的标准<a href="https://baike.baidu.com/item/%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A3" target="_blank" rel="noopener">编程接口</a>。它是一种与平台和语言无关的<a href="https://baike.baidu.com/item/%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E6%8E%A5%E5%8F%A3" target="_blank" rel="noopener">应用程序接口</a>(API),它可以动态地访问程序和脚本，更新其内容、结构和<a href="https://baike.baidu.com/item/www/109924" target="_blank" rel="noopener">www</a>文档的风格(目前，HTML和XML文档是通过说明部分定义的)。文档可以进一步被处理，处理的结果可以加入到当前的页面。<a href="https://baike.baidu.com/item/DOM/50288" target="_blank" rel="noopener">DOM</a>是一种基于树的<a href="https://baike.baidu.com/item/API/10154" target="_blank" rel="noopener">API</a>文档，它要求在处理过程中整个文档都表示在<a href="https://baike.baidu.com/item/%E5%AD%98%E5%82%A8%E5%99%A8" target="_blank" rel="noopener">存储器</a>中。</p>
<p>DOM又称为文档树模型</p>
<p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmv4zolaj30qx0ej0vu.jpg" alt=""></p>
<ul>
<li>文档：一个网页可以称为文档</li>
<li>节点：网页中的所有内容都是节点（标签、属性、文本、注释等）</li>
<li>元素：网页中的标签</li>
<li>属性：标签的属性</li>
</ul>
<h2 id="2、DOM经常进行的操作"><a href="#2、DOM经常进行的操作" class="headerlink" title="2、DOM经常进行的操作"></a>2、DOM经常进行的操作</h2><ul>
<li>获取元素</li>
<li>对元素进行操作(设置其属性或调用其方法)</li>
<li>动态创建元素</li>
<li>事件(什么时机做相应的操作)</li>
</ul>
<h2 id="3、获取页面元素"><a href="#3、获取页面元素" class="headerlink" title="3、获取页面元素"></a>3、获取页面元素</h2><h3 id="3-1-为什么要获取页面元素"><a href="#3-1-为什么要获取页面元素" class="headerlink" title="3.1 为什么要获取页面元素"></a>3.1 为什么要获取页面元素</h3><p>例如：我们想要操作页面上的某部分(显示/隐藏，动画)，需要先获取到该部分对应的元素，才进行后续操作</p>
<h3 id="3-2-根据id获取元素"><a href="#3-2-根据id获取元素" class="headerlink" title="3.2  根据id获取元素"></a>3.2  根据id获取元素</h3><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> div = <span class="built_in">document</span>.getElementById(<span class="string">'main'</span>);</span><br></pre></td></tr></tbody></table></figure>

<h3 id="3-3-根据标签名获取元素"><a href="#3-3-根据标签名获取元素" class="headerlink" title="3.3 根据标签名获取元素"></a>3.3 根据标签名获取元素</h3><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> divs = <span class="built_in">document</span>.getElementsByTagName(<span class="string">'div'</span>);</span><br></pre></td></tr></tbody></table></figure>

<p>返回的是一个集合，不是数组，可以认为是伪数组。</p>
<p>我们获取了元素后，可以对其进行操作，但是我们往往都是在触发了某个事件的时候才会对元素进行操作。</p>
<p>什么是事件呢？</p>
<h1 id="十一、事件"><a href="#十一、事件" class="headerlink" title="十一、事件"></a>十一、事件</h1><h2 id="1、什么是事件"><a href="#1、什么是事件" class="headerlink" title="1、什么是事件"></a>1、什么是事件</h2><p>当什么时候做什么事情 ，</p>
<p> 触发-响应</p>
<h2 id="2、事件三要素"><a href="#2、事件三要素" class="headerlink" title="2、事件三要素"></a>2、事件三要素</h2><ul>
<li>事件源:触发(被)事件的元素</li>
<li>事件名称: click 点击事件</li>
<li>事件处理程序:事件触发后要执行的代码(函数形式)</li>
</ul>
<h2 id="3、事件的基本使用"><a href="#3、事件的基本使用" class="headerlink" title="3、事件的基本使用"></a>3、事件的基本使用</h2><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> box = <span class="built_in">document</span>.getElementById(<span class="string">'box'</span>);</span><br><span class="line">box.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'代码会在box被点击后执行'</span>);</span><br><span class="line">};</span><br></pre></td></tr></tbody></table></figure>

<p>4、案例</p>
<ul>
<li>点击按钮切换图片</li>
</ul>
<h1 id="十二、属性操作"><a href="#十二、属性操作" class="headerlink" title="十二、属性操作"></a>十二、属性操作</h1><h2 id="1、属性基本操作"><a href="#1、属性基本操作" class="headerlink" title="1、属性基本操作"></a>1、属性基本操作</h2><figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> link = <span class="built_in">document</span>.getElementById(<span class="string">'link'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(link.href);</span><br><span class="line"><span class="built_in">console</span>.log(link.title);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> pic = <span class="built_in">document</span>.getElementById(<span class="string">'pic'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(pic.src);</span><br></pre></td></tr></tbody></table></figure>

<p><strong>案例：点击按钮显示隐藏div</strong>（作业）</p>
<p>现在已经实现了div的隐藏，下面可以div的展示，注意按钮上的文字要变成 “显示”</p>
<h2 id="2、innerHTML和innerText"><a href="#2、innerHTML和innerText" class="headerlink" title="2、innerHTML和innerText"></a>2、innerHTML和innerText</h2><pre><code>innerHTML  innerText
获取开始标签和结束标签之间的内容
innerHTML  获取内容的时候，如果内容中有标签，会把标签也获取到，原封不动把内容获取到
innerText  获取内容的时候，如果内容中有标签，会把标签过滤掉</code></pre><h1 id="十三、BOM"><a href="#十三、BOM" class="headerlink" title="十三、BOM"></a>十三、BOM</h1><h2 id="1、BOM的概念"><a href="#1、BOM的概念" class="headerlink" title="1、BOM的概念"></a>1、BOM的概念</h2><p>BOM(Browser Object Model) 是指浏览器对象模型，浏览器对象模型提供了独立于内容的、可以与浏览器窗口进行互动的对象结构。BOM由多个对象组成，其中代表浏览器窗口的Window对象是BOM的顶层对象，其他对象都是该对象的子对象。</p>
<p>我们在浏览器中的一些操作都可以使用BOM的方式进行编程处理，</p>
<p>比如：刷新浏览器、后退、前进、在浏览器中输入地址等</p>
<h2 id="2、BOM的顶级对象window"><a href="#2、BOM的顶级对象window" class="headerlink" title="2、BOM的顶级对象window"></a>2、BOM的顶级对象window</h2><p>window是浏览器的顶级对象，当调用window下的属性和方法时，可以省略window。</p>
<h2 id="3、对话框"><a href="#3、对话框" class="headerlink" title="3、对话框"></a>3、对话框</h2><ul>
<li>alert()</li>
<li>prompt()</li>
<li>confirm()</li>
</ul>
<h2 id="4、页面加载事件"><a href="#4、页面加载事件" class="headerlink" title="4、页面加载事件"></a>4、页面加载事件</h2><p><strong>onload</strong></p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</span><br><span class="line">  <span class="comment">// 当页面加载完成执行</span></span><br><span class="line">  <span class="comment">// 当页面完全加载所有内容（包括图像、脚本文件、CSS 文件等）执行</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

<h2 id="5、定时器"><a href="#5、定时器" class="headerlink" title="5、定时器"></a>5、定时器</h2><h3 id="setTimeout-和clearTimeout"><a href="#setTimeout-和clearTimeout" class="headerlink" title="setTimeout()和clearTimeout()"></a>setTimeout()和clearTimeout()</h3><p>在指定的毫秒数到达之后执行指定的函数，只执行一次</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建一个定时器，1000毫秒后执行，返回定时器的标示</span></span><br><span class="line"><span class="keyword">var</span> timerId = setTimeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'Hello World'</span>);</span><br><span class="line">}, <span class="number">1000</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 取消定时器的执行</span></span><br><span class="line">clearTimeout(timerId);</span><br></pre></td></tr></tbody></table></figure>

<h2 id="6、-删除提示案例"><a href="#6、-删除提示案例" class="headerlink" title="6、 删除提示案例"></a>6、 删除提示案例</h2><h2 id="7、setInterval-和clearInterval"><a href="#7、setInterval-和clearInterval" class="headerlink" title="7、setInterval()和clearInterval()"></a>7、setInterval()和clearInterval()</h2><p>定时调用的函数，可以按照给定的时间(单位毫秒)周期调用函数</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建一个定时器，每隔1秒调用一次</span></span><br><span class="line"><span class="keyword">var</span> timerId = setInterval(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'你好'</span>);</span><br><span class="line">}, <span class="number">1000</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 取消定时器的执行</span></span><br><span class="line">clearInterval(timerId);</span><br></pre></td></tr></tbody></table></figure>

<h2 id="8、location对象"><a href="#8、location对象" class="headerlink" title="8、location对象"></a>8、location对象</h2><p>location可以获取或者设置浏览器地址栏的地址</p>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><input type="<span" class="string">"button"</span> name=<span class="string">""</span> value=<span class="string">"单击跳转"</span> id=<span class="string">"btn"</span>><br><span class="line">  <script type="<span" class="string">"text/javascript"</span>></span><br><span class="line">  <span class="keyword">var</span> btn = <span class="built_in">document</span>.getElementById(<span class="string">'btn'</span>);</span><br><span class="line">  btn.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">      <span class="built_in">window</span>.location.href = <span class="string">'http://www.baidu.com'</span>;</span><br><span class="line">  }</span><br></pre></td></tr></tbody></table></figure>

<h1 id="十四、偏移量"><a href="#十四、偏移量" class="headerlink" title="十四、偏移量"></a>十四、偏移量</h1><h2 id="1、offset常用属性"><a href="#1、offset常用属性" class="headerlink" title="1、offset常用属性"></a>1、offset常用属性</h2><ul>
<li>offsetParent用于获取定位的父级元素</li>
</ul>
<figure class="highlight js"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> box = <span class="built_in">document</span>.getElementById(<span class="string">'box'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(box.offsetParent);</span><br><span class="line"><span class="built_in">console</span>.log(box.offsetLeft);</span><br><span class="line"><span class="built_in">console</span>.log(box.offsetTop);</span><br><span class="line"><span class="built_in">console</span>.log(box.offsetWidth);</span><br><span class="line"><span class="built_in">console</span>.log(box.offsetHeight);</span><br></pre></td></tr></tbody></table></figure>

<p><img src="https://ws1.sinaimg.cn/large/006doHETly1g2lmwsv2d6j30qo0fawfx.jpg" alt></p>
</body></html>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/前端/" rel="tag"># 前端</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/05/01/CSS/" rel="next" title="CSS">
                <i class="fa fa-chevron-left"></i> CSS
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/07/25/upload-labs通关手册/" rel="prev" title="upload-labs通关手册">
                upload-labs通关手册 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/touxiang.jpg"
                alt="GodPang" />
            
              <p class="site-author-name" itemprop="name">GodPang</p>
              <p class="site-description motion-element" itemprop="description">一只一直在努力的胖子</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/GodPang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/c8a45218e240" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://lengjibo.github.io/" title="冷逸" target="_blank">冷逸</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://test482.github.io" title="Eliot's Blog" target="_blank">Eliot's Blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://prontosil.club/" title="百浪多息" target="_blank">百浪多息</a>
                  </li>
                
              </ul>
            </div>
          

          <div id="music163player">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=38592976&auto=1&height=66"></iframe>
</div>

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#null"><span class="nav-number">1.</span> <span class="nav-text">没学明白呢QAQ</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、JavaScript现在的意义-应用场景"><span class="nav-number"></span> <span class="nav-text">1、JavaScript现在的意义(应用场景)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、JavaScript和HTML、CSS的区别"><span class="nav-number"></span> <span class="nav-text">2、JavaScript和HTML、CSS的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、JavaScript的组成"><span class="nav-number"></span> <span class="nav-text">3、JavaScript的组成</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1、ECMAScript-JavaScript的核心"><span class="nav-number">1.</span> <span class="nav-text">3.1、ECMAScript - JavaScript的核心</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2、BOM-浏览器对象模型"><span class="nav-number">2.</span> <span class="nav-text">3.2、BOM - 浏览器对象模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3、DOM-文档对象模型"><span class="nav-number">3.</span> <span class="nav-text">3.3、DOM - 文档对象模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4、JavaScript的书写位置"><span class="nav-number">4.</span> <span class="nav-text">3.4、JavaScript的书写位置</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、变量"><span class="nav-number"></span> <span class="nav-text">二、变量</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、什么是变量"><span class="nav-number">1.</span> <span class="nav-text">1、什么是变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、如何使用变量"><span class="nav-number">2.</span> <span class="nav-text">2、如何使用变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、变量在内存中的存储"><span class="nav-number">3.</span> <span class="nav-text">3、变量在内存中的存储</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4、变量的命名规则和规范"><span class="nav-number">4.</span> <span class="nav-text">4、变量的命名规则和规范</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5、交换两个变量中的值-案例"><span class="nav-number">5.</span> <span class="nav-text">5、交换两个变量中的值(案例)</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、数据类型"><span class="nav-number"></span> <span class="nav-text">三、数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、Number类型"><span class="nav-number"></span> <span class="nav-text">1、Number类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、String类型"><span class="nav-number"></span> <span class="nav-text">2、String类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-1-转义符"><span class="nav-number">1.</span> <span class="nav-text">2.2.1 转义符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-2-字符串长度"><span class="nav-number">2.</span> <span class="nav-text">2.2.2 字符串长度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-3-字符串拼接"><span class="nav-number">3.</span> <span class="nav-text">2.2.3 字符串拼接</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、Boolean类型"><span class="nav-number"></span> <span class="nav-text">3、Boolean类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、Undefined和Null"><span class="nav-number"></span> <span class="nav-text">4、Undefined和Null</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、获取变量的类型"><span class="nav-number"></span> <span class="nav-text">5、获取变量的类型</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、注释"><span class="nav-number"></span> <span class="nav-text">四、注释</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-单行注释"><span class="nav-number"></span> <span class="nav-text">4.1 单行注释</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-多行注释"><span class="nav-number"></span> <span class="nav-text">4.2 多行注释</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#五、操作符"><span class="nav-number"></span> <span class="nav-text">五、操作符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#5-1-算术运算符"><span class="nav-number"></span> <span class="nav-text">5.1 算术运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-2-一元运算符"><span class="nav-number"></span> <span class="nav-text">5.2  一元运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-3-逻辑运算符-布尔运算符"><span class="nav-number"></span> <span class="nav-text">5.3 逻辑运算符(布尔运算符)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-4-关系运算符-比较运算符"><span class="nav-number"></span> <span class="nav-text">5.4 关系运算符(比较运算符)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-5-赋值运算符"><span class="nav-number"></span> <span class="nav-text">5.5 赋值运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-6-运算符的优先级"><span class="nav-number"></span> <span class="nav-text">5.6 运算符的优先级</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#六、流程控制"><span class="nav-number"></span> <span class="nav-text">六、流程控制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#顺序结构"><span class="nav-number">1.</span> <span class="nav-text">顺序结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分支结构"><span class="nav-number">2.</span> <span class="nav-text">分支结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#循环结构"><span class="nav-number">3.</span> <span class="nav-text">循环结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-1-分支结构"><span class="nav-number"></span> <span class="nav-text">6.1 分支结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#if语句"><span class="nav-number">1.</span> <span class="nav-text">if语句</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-循环结构"><span class="nav-number"></span> <span class="nav-text">6.2 循环结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#while语句"><span class="nav-number">1.</span> <span class="nav-text">while语句</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#do…while语句"><span class="nav-number">2.</span> <span class="nav-text">do…while语句</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#for语句"><span class="nav-number">3.</span> <span class="nav-text">for语句</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#七、数组"><span class="nav-number"></span> <span class="nav-text">七、数组</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#为什么要学习数组"><span class="nav-number">1.</span> <span class="nav-text">为什么要学习数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组的概念"><span class="nav-number">2.</span> <span class="nav-text">数组的概念</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组的定义"><span class="nav-number">3.</span> <span class="nav-text">数组的定义</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#遍历数组"><span class="nav-number">4.</span> <span class="nav-text">遍历数组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组中新增元素"><span class="nav-number">5.</span> <span class="nav-text">数组中新增元素</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#八、函数"><span class="nav-number"></span> <span class="nav-text">八、函数</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、为什么要有函数"><span class="nav-number"></span> <span class="nav-text">一、为什么要有函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、什么是函数"><span class="nav-number"></span> <span class="nav-text">二、什么是函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-函数的定义"><span class="nav-number">1.</span> <span class="nav-text">2.1 函数的定义</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-函数的调用"><span class="nav-number">2.</span> <span class="nav-text">2.2 函数的调用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-函数的参数"><span class="nav-number">3.</span> <span class="nav-text">2.3 函数的参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-函数的返回值"><span class="nav-number">4.</span> <span class="nav-text">2.4 函数的返回值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#案例"><span class="nav-number">5.</span> <span class="nav-text">案例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#九、什么是对象"><span class="nav-number"></span> <span class="nav-text">九、什么是对象</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、JavaScript中的对象"><span class="nav-number"></span> <span class="nav-text">1、JavaScript中的对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、为什么要有对象"><span class="nav-number"></span> <span class="nav-text">2、为什么要有对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、-对象创建"><span class="nav-number"></span> <span class="nav-text">3、 对象创建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、属性和方法"><span class="nav-number"></span> <span class="nav-text">4、属性和方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、new关键字"><span class="nav-number"></span> <span class="nav-text">5、new关键字</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-6-this详解"><span class="nav-number"></span> <span class="nav-text">3.6 this详解</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十、什么是DOM"><span class="nav-number"></span> <span class="nav-text">十、什么是DOM</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、DOM的概念"><span class="nav-number"></span> <span class="nav-text">1、DOM的概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、DOM经常进行的操作"><span class="nav-number"></span> <span class="nav-text">2、DOM经常进行的操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、获取页面元素"><span class="nav-number"></span> <span class="nav-text">3、获取页面元素</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-为什么要获取页面元素"><span class="nav-number">1.</span> <span class="nav-text">3.1 为什么要获取页面元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-根据id获取元素"><span class="nav-number">2.</span> <span class="nav-text">3.2  根据id获取元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-根据标签名获取元素"><span class="nav-number">3.</span> <span class="nav-text">3.3 根据标签名获取元素</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十一、事件"><span class="nav-number"></span> <span class="nav-text">十一、事件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、什么是事件"><span class="nav-number"></span> <span class="nav-text">1、什么是事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、事件三要素"><span class="nav-number"></span> <span class="nav-text">2、事件三要素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、事件的基本使用"><span class="nav-number"></span> <span class="nav-text">3、事件的基本使用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十二、属性操作"><span class="nav-number"></span> <span class="nav-text">十二、属性操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、属性基本操作"><span class="nav-number"></span> <span class="nav-text">1、属性基本操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、innerHTML和innerText"><span class="nav-number"></span> <span class="nav-text">2、innerHTML和innerText</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十三、BOM"><span class="nav-number"></span> <span class="nav-text">十三、BOM</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、BOM的概念"><span class="nav-number"></span> <span class="nav-text">1、BOM的概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、BOM的顶级对象window"><span class="nav-number"></span> <span class="nav-text">2、BOM的顶级对象window</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、对话框"><span class="nav-number"></span> <span class="nav-text">3、对话框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、页面加载事件"><span class="nav-number"></span> <span class="nav-text">4、页面加载事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、定时器"><span class="nav-number"></span> <span class="nav-text">5、定时器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#setTimeout-和clearTimeout"><span class="nav-number">1.</span> <span class="nav-text">setTimeout()和clearTimeout()</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6、-删除提示案例"><span class="nav-number"></span> <span class="nav-text">6、 删除提示案例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7、setInterval-和clearInterval"><span class="nav-number"></span> <span class="nav-text">7、setInterval()和clearInterval()</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8、location对象"><span class="nav-number"></span> <span class="nav-text">8、location对象</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>
    


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">GodPang</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



  <div class="footer-custom">Hosted by <a target="_blank" rel="external nofollow" href="https://pages.github.com/">GitHub Pages</a></div>


        
<div class="busuanzi-count">
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</span></pre></td></tr></tbody></table></figure></60></p></body></html></div>








        
      </div>
    

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </article></div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'RAQiIXnddbLLbBRiBcDuJo3j-gzGzoHsz',
        appKey: 'rhBtL6nW6zYrDqLcVsPX4M51',
        placeholder: '大佬勿喷，文明交流',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

</div></div></div></main></div></body>
</html>
